package com.jiyun.student.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.baobei.mapper.BaoBeiMapper;
import com.jiyun.baobei.mapper.LuyiinMapper;
import com.jiyun.pojo.result.ResultVo;
import com.jiyun.pojo.student.Student;
import com.jiyun.student.mapper.StudentMapper;
import com.jiyun.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 文件名:StudentServiceimp
 * 创建者: 闫俊涛
 * 创建时间:2022/6/26 11:12
 * 描述:这是一个实例
 */
@Service
public class StudentServiceimp extends ServiceImpl<StudentMapper, Student>  implements StudentService {

    @Autowired
    private  StudentMapper studentMapper;
    @Override
    public List<Student> selectBySId(Integer id) {
        /*总数据*/
        return  studentMapper.selectBySId(id);
    }


    @Override
    public ResultVo mysc(Integer id, Integer status) {
        // 根据id查
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid",id);
        Student student = studentMapper.selectOne(queryWrapper);
        // status=1的时候就点赞+1
        if (status ==1 ) {
            // zan就++
           student.setZan(student.getZan()+1);
           // 修改数据
           studentMapper.updateById(student);
            return new ResultVo(200, "收藏成功", student.getStatuss());
            //  status等于0就点赞-1
        } else if (status ==0) {
            // 就-- zan==0
            student.setZan(student.getZan() - 1);
            return new ResultVo(501, "取消收藏", student.getStatuss());

        } else {
            return new ResultVo(501, "收藏失败", null);
        }

    }



}
